//
//  DMSearchDetailView.m
//  BaseAPP
//
//  Created by Evisu on 16/12/10.
//  Copyright © 2016年 evisum. All rights reserved.
//

#import "DMSearchDetailView.h"

@interface DMSearchDetailView ()

@property (nonatomic, strong)NSMutableArray *btns;

@property (nonatomic, strong)NSMutableArray *labs;

@end

@implementation DMSearchDetailView

- (NSMutableArray *)btns {

    if (!_btns) {
        
        _btns = [NSMutableArray array];
    }
    
    return _btns;
}

- (NSMutableArray *)labs {

    if (!_labs) {
        
        _labs = [NSMutableArray array];
    }
    
    return _labs;
}

- (instancetype)init {

    if (self = [super init]) {
        
        self.backgroundColor = KBACKGROUND_COLOR;
        [self initViews];
        [self layoutViews];
    }
    
    return self;
}

- (void)initViews {

    NSArray *imageNames = @[  @"fts_edu_sns_icon", @"fts_edu_article_icon", @"fts_edu_brandcontact_icon"];
    
    NSArray *titles = @[@"朋友圈", @"文章", @"公众号"];
    
    for (int i = 0; i < imageNames.count; i++) {
        
        //按钮
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = 100+i;
        [btn setImage:[UIImage imageNamed:imageNames[i]] forState:UIControlStateNormal];

        btn.backgroundColor = [UIColor whiteColor];
        
        [btn addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        btn.layer.cornerRadius = 31.0;
        btn.layer.masksToBounds = YES;
        
        [self addSubview:btn];
        [self.btns addObject:btn];
        
        //文字
        UILabel *lab = [[UILabel alloc] init];
        lab.font = [UIFont systemFontOfSize:14];
        lab.textColor = HEXColor(@"5D5D5D");
        lab.text = titles[i];
        [lab sizeToFit];
        [self addSubview:lab];
        [self.labs addObject:lab];
        
    }
}

- (void)layoutViews {

    UIButton *btnSns = self.btns[0];
    btnSns.sd_layout
    .topSpaceToView(self, 26)
    .leftSpaceToView(self, 32)
    .widthIs(62)
    .heightIs(62);
    
    UIButton *btnArticle = self.btns[1];
    btnArticle.sd_layout
    .topEqualToView(btnSns)
    .centerXEqualToView(self)
    .widthIs(62)
    .heightIs(62);
    
    
    UIButton *btnBrandcontact = self.btns[2];
    btnBrandcontact.sd_layout
    .topEqualToView(btnSns)
    .rightSpaceToView(self, 26)
    .widthIs(62)
    .heightIs(62);
    
    UILabel *labSns = self.labs[0];
    labSns.sd_layout
    .topSpaceToView(btnSns, 12)
    .centerXEqualToView(btnSns)
    .maxHeightIs(20);
    
    UILabel *labArticle = self.labs[1];
    labArticle.sd_layout
    .topSpaceToView(btnArticle, 12)
    .centerXEqualToView(btnArticle)
    .maxHeightIs(20);
    
    UILabel *labBrandcontact = self.labs[2];
    labBrandcontact.sd_layout
    .topSpaceToView(btnBrandcontact, 12)
    .centerXEqualToView(btnBrandcontact)
    .maxHeightIs(20);
}

- (void)didClickBtn:(UIButton *)btn {
    
    DMLog(@"%ld", (long)btn.tag);
    
    switch (btn.tag) {
        case 100:
            if ([self.searchDelegate respondsToSelector:@selector(DMSearchDetailViewDidClickedBtnTag:)]) {
                
                [self.searchDelegate DMSearchDetailViewDidClickedBtnTag:SearchTypeSns];
            }
            break;
            
        case 101:
            if ([self.searchDelegate respondsToSelector:@selector(DMSearchDetailViewDidClickedBtnTag:)]) {
                
                [self.searchDelegate DMSearchDetailViewDidClickedBtnTag:SearchTypeArticle];
            }
            break;
            
        case 102:
            if ([self.searchDelegate respondsToSelector:@selector(DMSearchDetailViewDidClickedBtnTag:)]) {
                
                [self.searchDelegate DMSearchDetailViewDidClickedBtnTag:SearchTypeBrandcontact];
            }
            break;
            
        default:
            break;
    }
}

@end
